package org.bean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.dal.gm_api.constant.OperateServerType;
import com.google.common.collect.Maps;
import com.sojoys.artifact.build.data.base.BasePojo;
import com.sojoys.artifact.constant.ServerStatusEnum;
import com.xiaoleilu.hutool.json.JSONObject;

/**
 * @author : DengYing
 * @CreateDate : 2017年12月16日 上午10:56:19
 * @Description ：服务器信息
 */
@SuppressWarnings("rawtypes")
public class GameServerInfo implements Comparable<GameServerInfo> {
    /** 服务器ID */
    private String id;
    /** 服务器状态 */
    private int status;
    /** 在线人数 */
    private int onlineCount;
    /** 注册人数 */
    private int playerCount;

    // -----------------------------------网络信息------------------------------------
    /** 内网IP */
    private String localHost;
    /** 外网IP */
    private String remoteHost;
    /** socket端口 */
    private int socketPort;
    /** Http端口 */
    private int httpPort;
    // ----------------------------------- 内存信息------------------------------------

    /** 物理内存，总的可使用的，单位：M */
    private int osPhysicalMemory;
    /** 物理内存，剩余，单位：M */
    private int osPhysicalFreeMemory;
    /** JVM内存，内存总量，单位：M */
    private int jvmTotalMemory;
    /** JVM内存，空闲内存量，单位：M */
    private int jvmFreeMemory;
    /** JVM内存，最大内存量，单位：M */
    private int jvmMaxMemory;

    // ------------------------------------ CPU 信息 -----------------------------------
    /** CPU 数量 */
    private int osCpuNumber;
    /** CPU 使用率 */
    private double oscpuRatio;

    /** 信息时间 */
    private long infoTime;
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public int getOnlineCount() {
        return onlineCount;
    }

    public void setOnlineCount(int onlineCount) {
        this.onlineCount = onlineCount;
    }

    public int getPlayerCount() {
        return playerCount;
    }

    public void setPlayerCount(int playerCount) {
        this.playerCount = playerCount;
    }

    public String getLocalHost() {
        return localHost;
    }

    public void setLocalHost(String localHost) {
        this.localHost = localHost;
    }

    public String getRemoteHost() {
        return remoteHost;
    }

    public void setRemoteHost(String remoteHost) {
        this.remoteHost = remoteHost;
    }

    public int getSocketPort() {
        return socketPort;
    }

    public void setSocketPort(int socketPort) {
        this.socketPort = socketPort;
    }

    public int getHttpPort() {
        return httpPort;
    }

    public void setHttpPort(int httpPort) {
        this.httpPort = httpPort;
    }

    public int getOsPhysicalMemory() {
        return osPhysicalMemory;
    }

    public void setOsPhysicalMemory(int osPhysicalMemory) {
        this.osPhysicalMemory = osPhysicalMemory;
    }

    public int getOsPhysicalFreeMemory() {
        return osPhysicalFreeMemory;
    }

    public void setOsPhysicalFreeMemory(int osPhysicalFreeMemory) {
        this.osPhysicalFreeMemory = osPhysicalFreeMemory;
    }

    public int getJvmTotalMemory() {
        return jvmTotalMemory;
    }

    public void setJvmTotalMemory(int jvmTotalMemory) {
        this.jvmTotalMemory = jvmTotalMemory;
    }

    public int getJvmFreeMemory() {
        return jvmFreeMemory;
    }

    public void setJvmFreeMemory(int jvmFreeMemory) {
        this.jvmFreeMemory = jvmFreeMemory;
    }

    public int getJvmMaxMemory() {
        return jvmMaxMemory;
    }

    public void setJvmMaxMemory(int jvmMaxMemory) {
        this.jvmMaxMemory = jvmMaxMemory;
    }

    public int getOsCpuNumber() {
        return osCpuNumber;
    }

    public void setOsCpuNumber(int osCpuNumber) {
        this.osCpuNumber = osCpuNumber;
    }

    public double getOscpuRatio() {
        return oscpuRatio;
    }

    public void setOscpuRatio(double oscpuRatio) {
        this.oscpuRatio = oscpuRatio;
    }

    @Override
    public String toString() {
        return toJsonString();
    }

    public JSONObject toJson() {
        JSONObject json = new JSONObject();
        json.put("id", id);
        json.put("status", status);
        json.put("onlineCount", onlineCount);
        json.put("playerCount", playerCount);
        json.put("localHost", localHost);
        json.put("remoteHost", remoteHost);
        json.put("socketPort", socketPort);
        json.put("httpPort", httpPort);
        json.put("osPhysicalMemory", osPhysicalMemory);
        json.put("osPhysicalFreeMemory", osPhysicalFreeMemory);
        json.put("jvmTotalMemory", jvmTotalMemory);
        json.put("jvmFreeMemory", jvmFreeMemory);
        json.put("jvmMaxMemory", jvmMaxMemory);
        json.put("osCpuNumber", osCpuNumber);
        json.put("oscpuRatio", oscpuRatio);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        json.put("infoTime", sdf.format(new Date(infoTime)));
        return json;
    }

    public String toJsonString() {
        return toJson().toString();
    }

    @Override
    public int compareTo(GameServerInfo gameServerInfo) {

        int r = Integer.compare(onlineCount, gameServerInfo.getOnlineCount());

        if (r == 0) {
            r = Integer.compare(jvmTotalMemory, gameServerInfo.getJvmTotalMemory());
        }
        return r;
    }

    static class A {
        private int count;

        public A(int count) {
            super();
            this.count = count;
        }

        @Override
        public String toString() {
            return "A [count=" + count + "]";
        }


    }

    public long getInfoTime() {
        return infoTime;
    }

    public void setInfoTime(long infoTime) {
        this.infoTime = infoTime;
    }
}
